package com.shengzai.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.List;

public class ScanData {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum","master,node1,node2");
        Connection con = ConnectionFactory.createConnection(conf);

        TableName tableName = TableName.valueOf("api_test:api_student");

        Table table = con.getTable(tableName);
        //全表扫描
        Scan scan = new Scan();



        ResultScanner scanner = table.getScanner(scan);

//        ResultScanner scanner = table.getScanner("students_info".getBytes());

        for (Result result : scanner) {
            List<Cell> cells = result.listCells();
            for (Cell cell : cells) {
                String family = Bytes.toString(CellUtil.cloneFamily(cell));
                String rows = Bytes.toString(CellUtil.cloneRow(cell));
                String values = Bytes.toString(CellUtil.cloneValue(cell));
                System.out.println(family+"\t"+rows+"\t"+values);
            }
        }
    }
}
